<?php
//Includes
require_once("MasterPage.php");
require_once("vcl/vcl.inc.php");
require_once("DB.php");
use_unit("forms.inc.php");
use_unit("extctrls.inc.php");
use_unit("stdctrls.inc.php");
use_unit("rtl.inc.php");

//Class definition
class RequestPassword extends MasterPage
{
   public $pnlInput = null;
   public $bRequestPassword = null;
   public $edUserName = null;
   public $lbUserName = null;
   public $lblInfo = null;
   public $pnLogin = null;

   function bRequestPasswordClick($sender, $params)
   {

      global $DB;

      //Declare the necessary variables
      $mail_to = $this->edUserName->Text;

      // Determine if the email address exists in the database and retrieve it if it does
      // $DB->q_query->close();
      $DB->q_query->SQL = "SELECT vchPassword FROM person WHERE vchEmail = '" . mysql_real_escape_string($mail_to) . "'";
      $DB->q_query->open();

      $cnt = $DB->q_query->RecordCount;
      if ($cnt == 1)
        $password = $DB->q_query->vchPassword;
      else
        $password = "";

      $DB->q_query->close();

      if($cnt == 1)
      {

         $mail_from = "janimyriam@gmail.com";
         $mail_sub = "Password reminder for Directory of Nonprofits in Second Life";
         $mail_mesg = "Your password is currently " . $password;

         //Check for success/failure of delivery
         if(mail($mail_to, $mail_sub, $mail_mesg, $mail_from))
            // echo "<span class='red'>E-mail has been sent successfully from $mail_sub to $mail_to</span>";
            $this->lbMessage->Caption = "Your password has been sent successfully to $mail_to";
         else
            // echo "<span class='red'>Failed to send the E-mail from $mail_sub to $mail_to</span>";
            $this->lbMessage->Caption = "Failed to send password to $mail_to";

      }
      else
      {
         $this->lbMessage->Caption = "The E-mail address you specified ($mail_to) was not found. Please try again.";
      }

   }
}

global $application;

global $RequestPassword;

//Creates the form
$RequestPassword = new RequestPassword($application);

//Read from resource file
$RequestPassword->loadResource(__FILE__);

//Shows the form
$RequestPassword->show();

?>